//
//  UploadImageApi.m
//  ICrEAM
//
//  Created by kuroro on 16/11/7.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "UploadImageApi.h"

@implementation UploadImageApi{
    NSDictionary *_images;
}

- (id)initWithImage:(NSDictionary *)images{
    self = [super init];
    if (self) {
        _images = images;
    }
    return self;
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPost;
}

- (NSString *)requestUrl {
    return [NSString stringWithFormat:@"http://%@/INFO_ICREAM_WEB/App/uploadPic",[[ICreamCache sharedInstance] stringForKey:kIPPath]];
}
- (AFConstructingBlock)constructingBodyBlock {
    return ^(id<AFMultipartFormData> formData) {
        
        [formData appendPartWithFileData:UIImageJPEGRepresentation(_images[@"0"], 0.5) name:@"FILE_OUTER_BIG" fileName:@"outerBig.jpeg" mimeType:@"jpeg"];
        [formData appendPartWithFileData:UIImageJPEGRepresentation(_images[@"1"], 0.5) name:@"FILE_INNER_BIG" fileName:@"innerBig.jpeg" mimeType:@"jpeg"];
        
            
        NSArray *appearanceArray = _images[@"2"];
        for (int i = 0 ; i<appearanceArray.count ; i++) {
            NSData *data = UIImageJPEGRepresentation(appearanceArray[i], 0.5);
            NSString *name = [NSString stringWithFormat:@"outer%d.jpeg",i];
            NSString *formKey = @"FILE_OUTER";
            NSString *type = @"jpeg";
            [formData appendPartWithFileData:data name:formKey fileName:name mimeType:type];
        }

        NSArray *innerArray = _images[@"3"];
        for (int i = 0 ; i<innerArray.count ; i++) {
            NSData *data = UIImageJPEGRepresentation(innerArray[i], 0.5);
            NSString *name = [NSString stringWithFormat:@"inner%d.jpeg",i];
            NSString *formKey = @"FILE_INNER";
            NSString *type = @"jpeg";
            [formData appendPartWithFileData:data name:formKey fileName:name mimeType:type];
        }
    };
}

//- (id)requestArgument {
//return @{
//             @"file":@""
//             };
//}

- (NSString *)responseImageId {
    NSDictionary *dict = self.responseJSONObject;
    return dict[@"imageId"];
}

@end
